package com.example.mapp;

import com.example.entity.authority.SystemAuthor;
import com.example.ext.entity.ExtSystemAuthor;
import com.example.mapp.buildSql.SystemAuthorMappSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by youkun on 2017/8/13.
 */
@Mapper
public interface SystemAuthorMapp {

    /**
     * 查询功能列表
     * @param extSystemAuthor
     * @return
     * @throws Exception
     */
    @SelectProvider(type = SystemAuthorMappSql.class,
            method = "querySystemAuthorList")
    public List<ExtSystemAuthor> querySystemAuthorList(ExtSystemAuthor extSystemAuthor) throws  Exception;


    @Insert(" insert into system_author (author_name,author_describe,author_url,parent_id,sys_type,author_id,author_type) " +
            "value (#{authorName},#{authorDescribe},#{authorUrl},#{parentId},#{sysType},#{authorId},#{authorType})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    public int addSystemAuthor(SystemAuthor systemAuthor) throws Exception;


    @Update(" update system_author " +
            "set author_name=#{authorName},author_describe=#{authorDescribe},author_url=#{authorUrl}," +
            "parent_id=#{parentId},author_id=#{authorId},author_type=#{authorType},sys_type=#{sysType} where id=#{id}")
    public int updateSystemAuthor(SystemAuthor systemAuthor) throws Exception;


    @Select("select s.id,s.author_describe, s.author_name,s.author_url," +
            "s.parent_id,s.author_icon,s.author_id,s.author_type,b.parent_name,s.sys_type from system_author as s left join (select author_name as parent_name," +
            "id from system_author) b on s.parent_id = b.id where s.id=#{id}")
    public ExtSystemAuthor querySystemAuthorById(@Param("id") String id)throws Exception;

    @Select("select s.id,s.author_describe, s.author_name,s.author_url," +
            "s.parent_id,s.author_icon,s.author_id,s.author_type,b.parent_name,s.sys_type from system_author as s left join (select author_name as parent_name," +
            "id from system_author) b on s.parent_id = b.id where s.author_name=#{name}")
    public ExtSystemAuthor querySystemAuthorByName(@Param("name") String name)throws Exception;


    @Delete("delete from system_author where id = #{id}")
    public int deleteSystemAuthorById(@Param("id") String id) throws Exception;


}
